package com.sx.micowell.module.countdown

import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.mvvm.base.ContainerActivity
import com.example.mvvm.base.data.DataBindingConfig
import com.gyf.immersionbar.ImmersionBar
import com.miloyu.modelnet.response.CourseVideoVO
import com.miloyu.modelnet.response.log
import com.sx.micowell.R
import com.sx.micowell.databinding.FragPlayCountdownBinding
import com.sx.micowell.framework.app.IntentKey
import com.sx.micowell.framework.app.MyFragment
import com.sx.micowell.framework.arouth.RouteManager
import com.sx.micowell.framework.arouth.RoutePath
import com.sx.micowell.framework.arouth.RoutePath.Companion.PLAY_COUNT_DOWN
import com.sx.widget.view.MyCountTimer


/**
 * @Description
 * @Author 梁浩文
 * @Date 2021/9/1 16:25
 */
@Route(path = RoutePath.COURSE_COUNT_DOWN)
class FragCourseCountDownFragment : MyFragment<FragPlayCountdownBinding, ContainerActivity>() {

    @Autowired(name = IntentKey.DATA)
    @JvmField
    var courseVideoData: CourseVideoVO? = null

    override fun getDataBindingConfig(): DataBindingConfig =
        DataBindingConfig(R.layout.frag_play_countdown)

    override fun initView() {
        myActivity.enableBack=false
        ImmersionBar.with(this).init()
        //倒计时总时间为10S，时间防止从9s开始显示
        val myCountTimer=MyCountTimer(4000, 1000, binding.btnCountTimer, "Go")
        myCountTimer.setCallBackCount {
            HANDLER.postDelayed({
                val bundle = Bundle()
                bundle.putSerializable(IntentKey.DATA, courseVideoData)
                startContainerActivity(
                    RouteManager.getInstance()
                        .getVideoPlayFragment(courseVideoData!!).javaClass.canonicalName
                    , bundle
                )
                activity?.finish()
            },400)
        }
        myCountTimer.start()
    }


    override fun initData() {
    }
}